package impl.persons;

import framework.Business;
import framework.PersonAdapter;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/** Implements "Anti Tit For Tat" personal strategy. */
public class AntiTitForTat extends PersonAdapter {
    private static Logger LOG = Logger.getLogger(AntiTitForTat.class);
    private Map<Object, Integer> history = new HashMap<Object, Integer>();

    @Override
    public String getShortName() {
        return "NTFT";
    }

    @Override
    public int deal(Object id) {
        if (history.containsKey(id)) {
            if (history.get(id) == Business.DEFECT) {
                return Business.COOPERATE;
            } else {
                return Business.DEFECT;
            }
        }
        return Business.DEFECT;
    }

    @Override
    public void dealed(Object id, int deal) {
        history.put(id, deal);
    }
}